package tcp;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : ClientTest
 * @Author : 54061
 * @Date: 2022/2/25 19:50
 */
public class ClientTest {
    public static void main(String[] args) throws IOException {
        //创建客户端对象
        Socket client = new Socket("127.0.0.1",6666);
        //获取客户端套接字的输出流
        OutputStream os = client.getOutputStream();
        //输出数据
        os.write("hello,Tcp server".getBytes());
        //获取输入流
        InputStream is = client.getInputStream();
        byte[] b = new byte[1024];
        int length = is.read(b);
        System.out.println("new String(b,0,length) = " + new String(b,0,length));
        //关闭资源
        is.close();
        os.close();
        client.close();

    }

}
